﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Lucene.Net.Index;
using Lucene.Net.Documents;

using ERPStore.Extensions;
using CloudSoft.Workflows;

namespace ERPStore.Indexers.Lucene.Workflows.Activities
{

	public sealed class AppendDocumentToCatalog : CodeActivity
	{
		public InArgument<IndexWriter> IndexWriter { get; set; }
		public InArgument<Document> Document { get; set; }

		protected override void Execute(CodeActivityContext context)
		{
			var indexWriter = context.GetValue(this.IndexWriter);
			var document = context.GetValue(this.Document);

			try
			{
				indexWriter.AddDocument(document);
			}
			catch(Exception ex)
			{
				context.ReportProgress(ex.Message);
			}
		}
	}
}
